//
//  UserHistoryManager.m
//  TopicDemo
//
//  Created by William Chang on 16/11/30.
//  Copyright © 2016年 InitialC. All rights reserved.
//

#import "UserHistoryManager.h"
#import <YYCache/YYCache.h>

@interface UserHistoryManager()

@property (strong, nonatomic) YYCache *userHistoryCache;

@end

@implementation UserHistoryManager

+ (instancetype)manager {
    static UserHistoryManager *instance = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        instance = [[UserHistoryManager alloc] init];
    });
    return instance;
}

- (instancetype)init {
    self = [super init];
    if (self) {
        self.userHistoryCache = [[YYCache alloc] initWithName:@"searchHistroy.userInfo"];
    }
    return self;
}
- (void)updateUserHistoryInfo:(id)userInfo {
    [self.userHistoryCache setObject:userInfo forKey:@"userHistoryInfo"];
}
- (NSMutableArray *)exportHistoryInfo {
    if ([self.userHistoryCache containsObjectForKey:@"userHistoryInfo"]) {
        NSMutableArray *historyArr = (NSMutableArray*)[self.userHistoryCache objectForKey:@"userHistoryInfo"];
        return historyArr;
    } else {
        NSMutableArray *historyArr = [NSMutableArray array];
        return historyArr;
    }
}

@end
